#' apply a box-cox transformation on variables can contain negative value
#'
#' @param onevariable a vector contains real numbers
#'

#' @export
boxCoxTrans<-function(onevariable)
{
  require(MASS)
  onev=onevariable
  if(min(onev)>100) lambda=seq(-100,100,by=0.01)
  else lambda=seq(-20,20,by=0.01)
  if(min(onev)<=0) onev=onev+abs(min(onev))+(1e-10)
  #browser()
  onet=boxcox(onev~1,lambda=lambda,plotit=F)
  lam=onet$x[match(max(onet$y),onet$y)]
  #browser()
  if(lam!=0) result=(onev^lam-1)/lam
  if(lam==0) result=log(onev)
  return(result)
}
